import Vue from 'vue'
import App from './App.vue'
import store from './store'
import router from './router'

Vue.config.devtools = true

// permission control
import '@/permission'

// import element-ui
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n 语言(英文)
import zhLocale from 'element-ui/lib/locale/lang/zh-CN' // 默认中文
Vue.use(ElementUI, {
  zhLocale
})

// import scss, icon   -- 此处暂定
import '@/styles/index.scss' // global css
import '@/assets/icon/iconfont.css'

import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
Vue.use(Treeselect)

Vue.config.productionTip = false

// if (process.env.NODE_ENV === 'development') {
//   require('../public/mock')  // dev下引入mock
// }

Vue.prototype.resetSetItem = function (key, newVal) {
  if (key === 'activeName') {
    // 创建一个StorageEvent事件
    var newStorageEvent = document.createEvent('StorageEvent')
    const storage = {
      setItem: function (k, val) {
        sessionStorage.setItem(k, val)
        // 初始化创建的事件
        newStorageEvent.initStorageEvent('activeName', false, false, k, null, val, null, null)

        // 派发对象
        window.dispatchEvent(newStorageEvent)
      }
    }
    return storage.setItem(key, newVal)
  }

  if (key === 'chapterId') {
    // 创建一个StorageEvent事件
    var newStorage = document.createEvent('StorageEvent')
    const storage = {
      setItem: function (k, val) {
        sessionStorage.setItem(k, val)
        // 初始化创建的事件
        newStorage.initStorageEvent('chapterId', false, false, k, null, val, null, null)

        // 派发对象
        window.dispatchEvent(newStorage)
      }
    }
    return storage.setItem(key, newVal)
  }
}
// json数组自定义方法
// eslint-disable-next-line no-extend-native
Array.prototype.indexOfJson = function (key) {
  for (let i = 0; i < this.length; i++) {
    if (this[i].id === key.id) {
      return i
    }
  }
  return -1
}

// 使用时间格式
import common from '@/utils/common.js'
Vue.use(common)
// 导入e-chart图表
import echarts from 'echarts'
Vue.prototype.$echarts = echarts

// v-chart图表
import VeBar from 'v-charts/lib/bar.common'
Vue.component(VeBar.name, VeBar)
// 导入环图
import VeRing from 'v-charts/lib/ring.common'
Vue.component(VeRing.name, VeRing)
// 导入折线图
import VeLine from 'v-charts/lib/line.common'
Vue.component(VeLine.name, VeLine)
// 导入条形图
import VeHistogram from 'v-charts/lib/histogram.common'
Vue.component(VeHistogram.name, VeHistogram)
// 导入雷达图
import VeRadar from 'v-charts/lib/radar.common'
Vue.component(VeRadar.name, VeRadar)
// 导入

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
